package com.uppfind.framework.mybatis.generator.generator.config.converts;

import com.uppfind.framework.mybatis.generator.generator.config.TypeConvert;
import com.uppfind.framework.mybatis.generator.generator.config.rules.DBColumnType;

/**
 * PostgreSQL 字段类型转换
 * Created by xuliugen on 2017/7/6.
 */
public class PostgreSqlTypeConvert implements TypeConvert {

    //TODO 进行具体的转换
    public DBColumnType processTypeConvert(String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("char") || t.contains("text")) {
            return DBColumnType.POSTGRESQL_STRING;
        } else if (t.contains("bigint")) {
            return DBColumnType.POSTGRESQL_LONG;
        } else if (t.contains("int")) {
            return DBColumnType.POSTGRESQL_INTEGER;
        } else if (t.contains("date") || t.contains("time") || t.contains("year")) {
            return DBColumnType.POSTGRESQL_DATE;
        } else if (t.contains("text")) {
            return DBColumnType.POSTGRESQL_STRING;
        } else if (t.contains("bit")) {
            return DBColumnType.POSTGRESQL_BOOLEAN;
        } else if (t.contains("blob")) {
            return DBColumnType.POSTGRESQL_BYTE_ARRAY;
        } else if (t.contains("float")) {
            return DBColumnType.POSTGRESQL_FLOAT;
        } else if (t.contains("double")) {
            return DBColumnType.POSTGRESQL_DOUBLE;
        } else if (t.contains("json") || t.contains("enum")) {
            return DBColumnType.POSTGRESQL_STRING;
        }
        return DBColumnType.POSTGRESQL_STRING;
    }

}
